<template>
  <div class="passwordBox">
    <form action="javascript:;" method="get">
      <div class="passwordBox-sub one">
        <div class="oldPassword">{{$t('userAdmin.info.password.name01')}}</div>
        <div class="passwordVal"><input type="text" maxlength="18"  autocomplete="off" id="content01-p" v-model="userPassword"
                                        :placeholder="$t('userAdmin.info.password.passwordInfo')"></div>
        <div class="tips" style="height: 20px;" id="tips01-p">{{$t('userAdmin.info.password.tip01')}}</div>
      </div>

      <div  class="passwordBox-sub">
        <div class="newPassword">{{$t('userAdmin.info.password.name02')}}</div>
        <div class="passwordVal"><input type="password" maxlength="18"  autocomplete="off" id="content02-p" v-model="newPassword"></div>
        <div class="tips" style="height: 20px;" id="tips02-p">{{$t('userAdmin.info.password.tip03')}}</div>
      </div>

      <div  class="passwordBox-sub">
        <div class="rePassword">{{$t('userAdmin.info.password.name03')}}</div>
        <div class="passwordVal"><input type="password" maxlength="18"  autocomplete="off" id="content03-p" v-model="reNewPassword"></div>
        <div class="tips" style="height: 20px;" id="tips03-p">{{$t('userAdmin.info.password.tip03')}}</div>
      </div>

      <div class="controller">
        <div class="passwordSubmit"><input type="submit" :value="$t('userAdmin.info.password.submit')" id="submit-p" @click="onclickSubOfP()"></div>
        <div class="passwordReset"><input type="reset" :value="$t('userAdmin.info.password.reset')" id="reset-p" @click="onclickReOfP"></div>
      </div>
    </form>
  </div>
</template>

<script>
    export default {
        name: "UserAdminInfo-password",
        data(){
            return{
                userPassword:'',
                newPassword:'',
                reNewPassword:'',
                baseURL:'http://localhost:8081/user/update/password/'
            }
        },
        methods:{
            onclickSubOfP() {
                if(this.userPassword.trim() == "" || this.newPassword.trim() == "" || this.newPassword != this.reNewPassword){
                    for (let i =2;i<4;i++){
                        document.getElementById("tips0"+i+"-p").style.display="block"
                        document.getElementById("content0"+i+"-p").style.border = "1px solid rgb(250, 37, 0)"
                    }
                }else{
                    for (let i =1;i<4;i++){
                        document.getElementById("tips0"+i+"-p").style.display="none"
                        document.getElementById("content0"+i+"-p").style.border = "1px solid rgb(216, 216, 216)"
                    }
                    this.axios.post(this.baseURL+this.userPassword+"/"+this.newPassword).then((res)=>{
                        if (res.data==true){
                            document.getElementById("tips01-p").style.display="none"
                            document.getElementById("content01-p").style.border = "1px solid rgb(216, 216, 216)"
                            this.successOpt(this.$t('userAdmin.info.password.optSuccess'))
                        } else if (res.data == 'error') {
                            document.getElementById("tips01-p").style.display="block"
                            document.getElementById("content01-p").style.border = "1px solid rgb(250, 37, 0)"
                        } else {
                            this.warningOpt(this.$t('userAdmin.info.password.Operation'))
                        }
                    }).catch(
                        exception=>{
                            console.log(exception)
                        }
                    )
                }
            },
            onclickReOfP() {
                for (let i =1;i<4;i++){
                    document.getElementById("tips0"+i+"-p").style.display="none"
                    document.getElementById("content0"+i+"-p").style.border = "1px solid rgb(216, 216, 216)"
                }
            },

            successOpt(message) {
                this.$notify({
                    title: this.$t('notify.success'),
                    message: message,
                    type: 'success'
                })
            },
            failOpt(message) {
                this.$notify.error({
                    title: this.$t('notify.error'),
                    message: message
                });
            }
        }
    }
</script>

<style scoped>
  .passwordBox{
    margin: 10px auto;
    width: 930px;
    height: 240px;
    background-color: rgba(255, 255, 255, 0.9);
    border: 1px solid rgb(226, 226, 226);
    border-radius: 3px;
    position: relative;
    letter-spacing: 1px;
  }
  .passwordBox-sub{
    height: 60px;
    position: relative;
  }
  .one{
    margin-top: 13px;
  }
  .passwordBox-sub div{
    float: left;
  }
  .oldPassword,.newPassword,.rePassword{
    width: 85px;
    margin-left: 30px;
    text-align: left;
    line-height: 35px;
    font-size: 15px;
    color: rgb(80, 80, 80);
  }
  .passwordVal{
    width: 600px;
    margin-left: 10px;
  }
  .passwordVal input{
    width: 650px;
    height: 31px;
    border: 1px solid rgb(216, 216, 216);
    background-color: transparent;
    /* border: 1px solid rgb(250, 37, 0); */
    color: rgb(105, 105, 105);
    border-radius: 3px;
    padding-left: 15px;
    transition: 0.3s;
  }
  .controller{
    width: 670px;
    height: 50px;
    margin-left: 125px;
  }
  .passwordSubmit, .passwordReset{
    float: left;
    width: 250px;
  }
  .passwordSubmit input, .passwordReset input{
    width: 320px;
    height: 35px;
    border: 1px solid rgb(138, 138, 138);
    color: rgb(241, 241, 241);
    border-radius: 3px;
    background-color: cadetblue;
  }
  .passwordSubmit input:hover{
    background-color: #00988a;
    color: rgb(255, 255, 255);
  }
  .passwordSubmit input:active{
    background-color: #047c70;
  }
  .passwordReset{
    margin-left: 100px;
  }
  .passwordReset input{
    border: 1px solid rgb(216, 216, 216);
    color: rgb(104, 104, 104);
    background-color: white;
  }
  .passwordReset input:hover{
    background-color: rgb(215, 236, 236);
    color: rgb(73, 157, 160);
    border: 1px solid rgb(73, 157, 160);
  }
  .passwordReset input:active{
    border: 1px solid rgb(0, 0, 0);
  }
  .tips{
    width: 700px;
    font-size: 12px;
    color: rgb(255, 60, 25);
    position: absolute;
    top: 40px;
    left: 124px;
    display: none;
    transition: 0.3s;
  }
</style>
